<template>
  <view class="container">
    <view class="header">
      <text class="title">设置</text>
    </view>
    
    <view class="settings-section">
      <view class="section-title">数据源管理</view>
      <DataSourceManager />
    </view>
    
    <view class="settings-section">
      <view class="section-title">通知设置</view>
      <view class="setting-item">
        <text>场地空闲提醒</text>
        <switch checked />
      </view>
      
      <view class="setting-item">
        <text>热门场地推送</text>
        <switch />
      </view>
    </view>
    
    <view class="settings-section">
      <view class="section-title">其他设置</view>
      <view class="setting-item">
        <text>默认查询范围</text>
        <picker mode="selector" :range="rangeOptions" @change="rangeChange">
          <view class="picker">{{ selectedRange }}</view>
        </picker>
      </view>
      
      <view class="setting-item">
        <text>时间偏好</text>
        <picker mode="selector" :range="timeOptions" @change="timeChange">
          <view class="picker">{{ selectedTimePreference }}</view>
        </picker>
      </view>
    </view>
    
    <view class="action-section">
      <button class="save-button" @click="saveSettings">保存设置</button>
    </view>
  </view>
</template>

<script>
import DataSourceManager from '@/components/DataSourceManager.vue';

export default {
  components: {
    DataSourceManager
  },
  data() {
    return {
      rangeOptions: ['1公里', '3公里', '5公里', '10公里'],
      selectedRange: '3公里',
      timeOptions: ['上午', '下午', '晚上', '全天'],
      selectedTimePreference: '全天'
    };
  },
  methods: {
    
    rangeChange(e) {
      this.selectedRange = this.rangeOptions[e.detail.value];
    },
    
    timeChange(e) {
      this.selectedTimePreference = this.timeOptions[e.detail.value];
    },
    
    saveSettings() {
      uni.showToast({
        title: '设置已保存',
        icon: 'success'
      });
      
      // 这里应该保存设置到本地存储或服务器
      console.log('保存设置：', {
        selectedRange: this.selectedRange,
        selectedTimePreference: this.selectedTimePreference
      });
    }
  }
};
</script>

<style lang="scss">
.container {
  padding: 20rpx;
}

.header {
  text-align: center;
  margin-bottom: 30rpx;
}

.title {
  font-size: 36rpx;
  font-weight: bold;
  color: $uni-color-title;
}

.settings-section {
  background-color: white;
  border-radius: 8rpx;
  padding: 20rpx;
  margin-bottom: 30rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
}

.section-title {
  font-size: 32rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
  padding-bottom: 20rpx;
  border-bottom: 1px solid $uni-border-color;
}

.data-source-list {
  margin-bottom: 20rpx;
}

.data-source-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 0;
  border-bottom: 1px solid $uni-border-color;
  
  &:last-child {
    border-bottom: none;
  }
}

.source-info {
  display: flex;
  flex-direction: column;
}

.source-name {
  font-size: 28rpx;
  margin-bottom: 10rpx;
}

.source-status {
  font-size: 24rpx;
  
  &.active {
    color: $uni-color-success;
  }
}

.add-source-button {
  width: 100%;
  padding: 20rpx;
  background-color: $uni-bg-color-grey;
  border-radius: 8rpx;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 0;
  border-bottom: 1px solid $uni-border-color;
  
  &:last-child {
    border-bottom: none;
  }
}

.picker {
  padding: 10rpx 20rpx;
  background-color: $uni-bg-color-grey;
  border-radius: 8rpx;
}

.action-section {
  text-align: center;
}

.save-button {
  width: 80%;
  padding: 20rpx;
  background-color: $uni-color-primary;
  color: white;
  border-radius: 8rpx;
}
</style>